package com.mycompany.j2eem.Mapper.wcymapper;

import com.mycompany.j2eem.Entity.PersonalInformation;
import com.mycompany.j2eem.Entity.Test;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author asus
 */
public interface LoginMapper {

    //获取Account_id
    @Select("SELECT id from Account where username =#{username}")
    String getAccountId(@Param("username") String username);

    //获取密码
    @Select("SELECT passwd FROM Account where username = #{username}")
    String login(@Param("username") String username);

    //修改密码
    @Update("Update Account set passwd = #{passwd} where username=#{username}")
    boolean changePassword(@Param("username") String username, @Param("passwd") String passwd);

    //注册
    @Insert("Insert into Account(username,passwd,state) value(#{username},#{passwd},#{state})")
    int register(@Param("username") String username, @Param("passwd") String passwd, @Param("state") String state);

    //获取生日性别头像,昵称
    @Select("SELECT id,picture,sex,birthday,nickname From User where Account_id = #{username}")
    PersonalInformation getInformation(@Param("username") String username);

    //获取生日性别头像,昵称
    @Select("SELECT id,picture,sex,birthday,nickname From User where id = #{id}")
    PersonalInformation getInformationById(@Param("id") String id);

    //更改个人信息
    @Update("Update User set birthday=#{birthday},nickname=#{nickname},sex=#{sex} where Account_id = #{Account_id}")
    int updatePersonalInformation(@Param("birthday") String birthday, @Param("nickname") String nickname, @Param("sex") String sex, @Param("Account_id") String account_id);

    //更改头像头像
    @Update("Update User set picture=#{picture},picture_old=#{picture_old} where Account_id =#{Account_id}")
    int updatePicture(@Param("picture") String picture, @Param("Account_id") String Account_id, @Param("picture_old") String picture_old);

    //获取个人头像
    @Select("Select picture from User where Account_id = #{Account_id}")
    String getPicture(@Param("Account_id") String Account_id);

    //获取旧头像
    @Select("Select old_picture from User where Account_id = #{Account_id}")
    String getOldPicture(@Param("Account_id") String Account_id);

    //初始化个人信息
    @Insert("Insert into User(Account_id,picture,nickname,birthday,sex,picture_old) value(#{Account_id},#{picture},#{nickname},now(),#{sex},#{picture_old})")
    int initInformation(@Param("Account_id") String Account_id, @Param("picture") String picture, @Param("nickname") String nickname, @Param("sex") String sex, @Param("picture_old") String picture_old);

    //初始化个人收藏夹
    @Insert("Insert into Favorite(Account_id,Favorite_name_id,private) value(#{account_id},#{favorite_name},'public')")
    int initFavorite(@Param("account_id") String account_id, @Param("favorite_name") String favorite_name);

    //初始化个人仓库
    @Insert("Insert into PersonalHub(Account_id,PersonalHub_name_id) value(#{account_id},#{favorite_name})")
    int initHub(@Param("account_id") String account_id, @Param("favorite_name") String favorite_name);

    //关注用户
    @Insert("INSERT INTO follow(Account_id_a,Account_id_b) VALUES(#{account_a},#{account_b})")
    int connerUser(@Param("account_a") String account_a, @Param("account_b") String account_b);

    //取消关注
    @Delete("Delete from follow where Account_id_a = #{account_a} and Account_id_b = #{account_b}")
    int deleteConnerUser(@Param("account_a") String account_a, @Param("account_b") String account_b);

    @Insert("Select * from Operation(operation) value(#{abc})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int test(Test test);

    @Select("Select id from  Account where username='1111'")
    String testnull();

    //获取关注列表
    @Select("Select Account_id_b from follow where Account_id_a = #{id}")
    List<String> getList(@Param("id") String id);

    //获取粉丝列表
    @Select("Select Account_id_a from follow where Account_id_b = #{id}")
    List<String> getFansList(@Param("id") String id);

    //获取用户ID
    @Select("Select id from Account")
    List<String> getUserId();

}
